stack segment at 500h
	dw 128 dup(?)
	tos label word
stack ends

code segment
main proc far
	assume cs:code,ss:stack
start:
	mov ax,stack
	mov ss,ax
	mov sp,offset tos

	push ds
	sub ax,ax
	push ax

	mov ax,4321h
	call htoa
	ret
main endp

htoa proc near
	cmp ax,15	;ax = 4321	;ax = 0432	;ax = 0043
	jle b1
	push ax	
	push bp
	mov bp,sp	
	mov bx,[bp+2]	;bx = 4321	
	and bx,000fh	;bx = 0001	;bx = 0002h	;bx = 0003h
	mov [bp+2],bx	
	pop bp
	mov cl,4
	shr ax,cl	;ax = 0432	;ax = 0043	;ax = 0004
	call htoa
	pop ax
b1:
	add al,30h
	cmp al,3ah
	jl printit
	add al,7h
printit:
	mov dl,al
	mov ah,2
	int 21h
	ret
htoa	endp
code ends
	end start
